home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB5 Code / Class 5 / Example5-1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-08-28  |  3.5 KB  |  111 lines

  1. VERSION 5.00
  2. Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
  3. Begin VB.Form frmSQLTester 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "SQL Tester"
  6.    ClientHeight    =   3540
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   6360
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3540
  14.    ScaleWidth      =   6360
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdTest 
  17.       Caption         =   "Test SQL Statement"
  18.       Height          =   495
  19.       Left            =   4080
  20.       TabIndex        =   4
  21.       TabStop         =   0   'False
  22.       Top             =   1920
  23.       Width           =   2175
  24.    End
  25.    Begin VB.TextBox txtSQLTester 
  26.       Height          =   1575
  27.       Left            =   120
  28.       MultiLine       =   -1  'True
  29.       ScrollBars      =   2  'Vertical
  30.       TabIndex        =   3
  31.       Top             =   1920
  32.       Width           =   3855
  33.    End
  34.    Begin MSDBGrid.DBGrid grdSQLTester 
  35.       Bindings        =   "Example5-1.frx":0000
  36.       Height          =   1695
  37.       Left            =   120
  38.       OleObjectBlob   =   "Example5-1.frx":0030
  39.       TabIndex        =   2
  40.       TabStop         =   0   'False
  41.       Top             =   120
  42.       Width           =   6135
  43.    End
  44.    Begin VB.Data datSQLTester 
  45.       Caption         =   "SQL Tester"
  46.       Connect         =   "Access"
  47.       DatabaseName    =   "c:\VBDB\Working\Biblio.mdb"
  48.       DefaultCursorType=   0  'DefaultCursor
  49.       DefaultType     =   2  'UseODBC
  50.       Exclusive       =   0   'False
  51.       Height          =   345
  52.       Left            =   4080
  53.       Options         =   0
  54.       ReadOnly        =   0   'False
  55.       RecordsetType   =   1  'Dynaset
  56.       RecordSource    =   ""
  57.       Top             =   3120
  58.       Width           =   2220
  59.    End
  60.    Begin VB.Label lblRecords 
  61.       Alignment       =   2  'Center
  62.       BackColor       =   &H00FFFFFF&
  63.       BorderStyle     =   1  'Fixed Single
  64.       Caption         =   "0"
  65.       BeginProperty Font 
  66.          Name            =   "MS Sans Serif"
  67.          Size            =   12
  68.          Charset         =   0
  69.          Weight          =   400
  70.          Underline       =   0   'False
  71.          Italic          =   0   'False
  72.          Strikethrough   =   0   'False
  73.       EndProperty
  74.       Height          =   495
  75.       Left            =   5040
  76.       TabIndex        =   1
  77.       Top             =   2520
  78.       Width           =   1215
  79.    End
  80.    Begin VB.Label Label1 
  81.       Caption         =   "Records Returned"
  82.       Height          =   495
  83.       Left            =   4080
  84.       TabIndex        =   0
  85.       Top             =   2520
  86.       Width           =   1215
  87.    End
  88. Attribute VB_Name = "frmSQLTester"
  89. Attribute VB_GlobalNameSpace = False
  90. Attribute VB_Creatable = False
  91. Attribute VB_PredeclaredId = True
  92. Attribute VB_Exposed = False
  93. Option Explicit
  94. Private Sub cmdTest_Click()
  95. 'Enable error handling
  96. On Error GoTo SQLError
  97. 'Read SQL statement and establish Recordsource
  98. datSQLTester.RecordSource = txtSQLTester.Text
  99. datSQLTester.Refresh
  100. 'Count records
  101. datSQLTester.Recordset.MoveLast
  102. datSQLTester.Recordset.MoveFirst
  103. lblRecords.Caption = datSQLTester.Recordset.RecordCount
  104. txtSQLTester.SetFocus
  105. Exit Sub
  106. 'If error occurs, report it in message box
  107. SQLError:
  108. MsgBox Error(Err.Number), vbExclamation + vbOKOnly, "SQL Error"
  109. Exit Sub
  110. End Sub
  111.